<template>
  <el-config-provider :locale="i18nLocale">
    <router-view v-show="getThemeConfig.lockScreenTime !== 0" />
    <Setings v-show="getThemeConfig.lockScreenTime !== 0" />
  </el-config-provider>
</template>

<script lang="ts" setup>
import {
	computed,
	getCurrentInstance,
	nextTick,
	onBeforeMount,
	onMounted,
	onUnmounted,
	ref,
	watch,
} from 'vue';
import { useStore } from '@/store';
import setIntroduction from '@/utils/setIconfont';
import Setings from '@/layout/navBars/breadcrumb/setings.vue';
import { Local, Session } from '@/utils/storage';
import { useRoute } from 'vue-router';
import other from '@/utils/other';
const store = useStore();
const route = useRoute();
const { proxy } = getCurrentInstance() as any;
const i18nLocale = ref();
// 获取布局配置信息
const getThemeConfig = computed(() => {
	return store.state.themeConfig.themeConfig;
});

// 设置初始化，防止刷新时恢复默认
onBeforeMount(() => {
	// 设置批量第三方 icon 图标
	setIntroduction.cssCdn();
	// 设置批量第三方 js
	setIntroduction.jsCdn();
});
onMounted(() => {
	nextTick(() => {
		proxy.mittBus.on('getI18nConfig', (locale: string) => (i18nLocale.value = locale));
		if (Local.get('themeConfig')) {
			store.dispatch('themeConfig/setThemeConfig', Local.get('themeConfig'));
			document.documentElement.style.cssText = Local.get('themeConfigStyle');
		}
		// 获取缓存中的全屏配置
		if (Session.get('isTagsViewCurrenFull')) {
			store.dispatch('tagsViewRoutes/setCurrenFullscreen', Session.get('isTagsViewCurrenFull'));
		}
	});
});
// 页面销毁时，关闭监听布局配置/i18n监听
onUnmounted(() => {
	proxy.mittBus.off('getI18nConfig', () => {});
});
// 监听路由的变化，设置网站标题
watch(
	() => route.path,
	() => {
		other.useTitle();
	}
);
</script>
